<!--
 * @Author: xuna
 * @Descripttion: 查看回款
-->
<template>
  <div class="paycollect-container">
    <el-form
      ref="formInline"
      :inline="true"
      :model="paycollectInfo"
      :label-position="labelPosition"
    >
      <el-row
        type="flex"
        justify="space-between"
        style="margin-bottom: 14px;padding-left: 60px;box-sizing:border-box;"
      >
        <el-col>
          <el-form-item label="日期:" prop="startTime">
            <el-date-picker
              v-model="paycollectInfo.startTime"
              type="date"
              class="sign-time"
              placeholder="开始日期"
              value-format="yyyy-MM-dd"
              :picker-options="statrPickOption"
            ></el-date-picker>
            ~
            <el-date-picker
              v-model="paycollectInfo.endTime"
              type="date"
              class="sign-time"
              placeholder="结束日期"
              value-format="yyyy-MM-dd"
              :picker-options="endPickOption"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col class="setting-btn">
          <el-form-item>
            <el-button class="settbtn reset-btn" @click="resetForm()">重置</el-button>
            <el-button class="settbtn search-btn" type="primary" @click="getTableList()">
              查询
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 表格 -->
    <div class="page-table-container">
      <wf-el-table
        :list="tableData"
        :total="total"
        :current="current"
        :loading="loading"
        @on-page-change="onPageChange"
      >
        <el-table-column type="index" label="序号" width="100"></el-table-column>
        <el-table-column
          v-for="item in propData"
          :key="item.prop"
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
        ></el-table-column>
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button type="text" class="handle-icon" @click="checkDetail(scope.row)">
              <img src="@/assets/img/check.png" alt="" />
              查看详情
            </el-button>
          </template>
        </el-table-column>
      </wf-el-table>
    </div>
    <!-- 回款详情组件 -->
    <Detail
      :is-open-detail="openCheck"
      :paycollet-row="paycolletRow"
      @closeDrawer="closeDrawer"
    ></Detail>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex';
  import WfElTable from '@/components/Table/index';
  import Detail from './components/Detail';
  import { getAdvanceMoneyBackList } from '@/api/careCard';
  export default {
    components: { WfElTable, Detail },
    data() {
      return {
        current: 1,
        total: 0,
        openCheck: false,
        loading: false,
        paycolletRow: {},
        tableData: [],

        propData: [
          {
            prop: 'createTime',
            label: '时间',
          },
          {
            prop: 'totalAmount',
            label: '累计分配总额',
          },
          {
            prop: 'totalRecoverAmount',
            label: '累计被撤回总额',
          },
          {
            prop: 'billTotalAmount',
            label: '已出账消费总额',
          },
          {
            prop: 'amount',
            label: '汇款（回款）金额',
          },
          {
            prop: 'balance',
            label: '当前欠费',
          },
          {
            prop: 'realName',
            label: '操作人',
          },
          {
            prop: 'remarks',
            label: '备注',
          },
        ],
        paycollectInfo: {
          startTime: null,
          endTime: null,
        },
        startTime: null,
        labelPosition: 'right',

        statrPickOption: {
          disabledDate: time => {
            if (this.paycollectInfo.endTime != null) {
              return (
                time.getTime() > new Date(this.paycollectInfo.endTime).getTime() - 8.64e6 ||
                time.getTime() < 1577808000000 ||
                time.getTime() > 1609344000000
              );
            } else {
              return time.getTime() < 1577808000000 || time.getTime() > 1609344000000;
            }
          },
        },
        endPickOption: {
          disabledDate: time => {
            if (this.paycollectInfo.startTime != null) {
              return (
                time.getTime() < new Date(this.paycollectInfo.startTime).getTime() - 8.64e7 ||
                time.getTime() < 1577808000000 ||
                time.getTime() > 1609344000000
              );
            } else {
              return time.getTime() < 1577808000000 || time.getTime() > 1609344000000;
            }
          },
        },
      };
    },
    ...mapGetters('user', ['userInfo']),
    organName() {
      return this.userInfo.organName;
    },
    activated() {
      this.getTableList();
    },
    methods: {
      initList(current, info) {
        this.loading = true;
        let objData = {
          organizationName: this.organName,
          pageCurrrent: current,
          pageSize: 10,
          startTime: info.startTime ? `${info.startTime} 00:00:00` : info.startTime,
          endTime: info.endTime ? `${info.endTime} 23:59:59` : info.endTime,
        };
        try {
          getAdvanceMoneyBackList(objData).then(res => {
            console.log(res);
            this.loading = false;
            if (res.status == 200) {
              this.tableData = res.data.records;
              this.total = res.data.total;
            }
          });
        } catch (error) {
          this.loading = false;
        }
      },
      getTableList() {
        this.initList(1, this.paycollectInfo);
      },
      resetForm() {
        this.$refs.formInline.resetFields();
        this.paycollectInfo.endTime = null;
        this.getTableList();
      },
      checkDetail(row) {
        this.openCheck = true;
        this.paycolletRow = row;
        console.log(this.paycolletRow);
      },
      closeDrawer(close) {
        this.openCheck = close;
      },
      onPageChange(data) {
        this.current = data.current;
        this.initList(this.current, this.paycollectInfo);
      },
    },
  };
</script>

<style lang="scss" scoped>
  @import '~@/styles/mixin.scss';
  .page-table-container {
    height: calc(100% - 86px);
  }
  .wf-table-wrapper {
    height: 100% !important;
  }
  /deep/.el-table__fixed-body-wrapper {
    top: 44px !important;
  }
  .paycollect-container {
    background-color: #efeef1;
    @include wh(100%, 100%);
    overflow: hidden;
    padding-top: 0 !important;
    /deep/.el-form--inline {
      background-color: #fff;
      border-radius: 7px;
      padding: 14px 17px 0 30px;
      box-sizing: border-box;
    }
    /deep/.el-form-item__label {
      @include font(14px, #7f848b, 400);
    }
    /deep/.el-input {
      background: rgba(255, 255, 255, 1);
      border-radius: 7px;
      border: 1px solid rgba(244, 240, 243, 1);
    }
    /deep/.el-table {
      border-radius: 7px;
    }
    /deep/.el-table th.gutter {
      display: table-cell !important;
    }
    .setting-btn {
      display: flex;
      justify-content: flex-end;
      .settbtn {
        @include wh(94px, 36px);
        border-radius: 7px;
      }
      .reset-btn {
        background: rgba(255, 254, 255, 1);
        border: 1px solid rgba(232, 228, 232, 1);
      }
      .search-btn {
        background-color: #3771e9;
      }
    }

    .handle-icon {
      @include font(14px, #353739, 400);
      margin-right: 15px;
      img {
        @include wh(23px, 23px);
        vertical-align: middle;
      }
    }
  }
  .sign-time {
    width: 180px;
    position: relative;
    margin: 0 4px;
  }
</style>
